package com.zzl.services.impl;

import com.zzl.entity.User;
import com.zzl.services.UserService;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserServicesImpl implements UserService {

    @Override
    public User login(Connection connection, User user) throws SQLException {
        User resultUser = null;
        String sql = "select * from t_user where userName = ? and password = ?";
        PreparedStatement pstmt = connection.prepareStatement(sql);

        pstmt.setString(1, user.getUserName());
        pstmt.setString(2, user.getPassword());
        ResultSet rs = pstmt.executeQuery();
        if (rs.next()) {
            resultUser = new User();
            resultUser.setUserName(rs.getString("userName"));
            resultUser.setPassword(rs.getString("password"));
        }
        return resultUser;
    }
}